/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Help.java
 *
 * Created on 2011-06-03, 15:40:26
 */

package trumpet.gui;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import org.w3c.dom.html.HTMLLabelElement;

/**
 *
 * @author Artur
 */
public class Help extends javax.swing.JFrame {

    /** Creates new form Help */
    public Help() {
        initComponents();
        this.loadHelp(0);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        ButtonClose = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TopicList = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        HelpLabelContent = new javax.swing.JLabel();

        jLabel1.setText("jLabel1");

        setTitle("Pomoc");

        ButtonClose.setText("Zamknij");
        ButtonClose.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ButtonCloseMouseClicked(evt);
            }
        });
        ButtonClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonCloseActionPerformed(evt);
            }
        });

        TopicList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Do czego służy Trumpet", "Widok listy kontaktów", "Dodawanie kontaktu", "Edycja kontaktu", "Usunięcie kontaktu", "Okno rozmowy", "Pisanie", "Wideokonferencja" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        TopicList.setSelectedIndex(0);
        TopicList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TopicListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(TopicList);

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        HelpLabelContent.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        jScrollPane2.setViewportView(HelpLabelContent);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ButtonClose)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 349, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ButtonClose)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ButtonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonCloseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ButtonCloseActionPerformed

    private void ButtonCloseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ButtonCloseMouseClicked
        this.setVisible(false);
    }//GEN-LAST:event_ButtonCloseMouseClicked

    private void TopicListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TopicListMouseClicked
        this.loadHelp(this.TopicList.getSelectedIndex());
}//GEN-LAST:event_TopicListMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Help().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonClose;
    private javax.swing.JLabel HelpLabelContent;
    private javax.swing.JList TopicList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables


    private static String readFileAsString(String filePath) throws java.io.IOException
    {
            StringBuilder fileData = new StringBuilder(1000);
            BufferedReader reader = new BufferedReader(new FileReader(filePath));
            char[] buf = new char[1024];
            int numRead=0;
            while((numRead=reader.read(buf)) != -1){
                fileData.append(buf, 0, numRead);
            }
            reader.close();
            return fileData.toString();
    }

    private void loadHelp(int num)
    {
        try {
            this.HelpLabelContent.setText(Help.readFileAsString("src/Data/help/" + num + ".html"));
        } catch (IOException e) {
            System.out.print("blad");
        }
    }
}
